package com.voice.server.repository;


import com.voice.server.entity.Device;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-04-23 11:54:50
 */
public interface DeviceRepository extends JpaRepository<Device,String> {

    Device findByUserIdAndId(String userId,String id);

    Device findByDeviceKey(String deviceKey);

    @Query("select new Device(deviceKey,pushType,matchText)  from Device where status=?1 and pushType is not null ")
    List<Device> findByStatus(Integer status);

    @Query("from Device where startTime is not null and startTime <> ''")
    List<Device> findByStartTimeIsNotBlank();

    @Query("update Device set status=?2 where deviceKey=?1")
    @Modifying
    void updateDeviceStatus(String deviceKey,int status);
}
